package edu.xkd.hormany_test3.hormany03_02.slice;

import edu.xkd.hormany_test3.hormany03_02.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Image;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        Button button = (Button) findComponentById(ResourceTable.Id_but1);
        Image image1 = (Image) findComponentById(ResourceTable.Id_image1);

        button.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                List<Integer> list=new ArrayList<>();
                list.add(ResourceTable.Media_girl1);
                list.add(ResourceTable.Media_girl2);
                list.add(ResourceTable.Media_girl3);
                list.add(ResourceTable.Media_girl4);
                list.add(ResourceTable.Media_girl5);
                list.add(ResourceTable.Media_girl6);
                list.add(ResourceTable.Media_girl7);
                list.add(ResourceTable.Media_girl8);
                list.add(ResourceTable.Media_girl8);
                list.add(ResourceTable.Media_girl9);
                // 随机获取容器里的一个元素
                Random random = new Random();
                int indexImage = random.nextInt(list.size());

                // 把获取到得元素显示image组件里
                image1.setImageAndDecodeBounds(list.get(indexImage));
            }
        });

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
